<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>脚手架-RuoYi-Vue 前后端分离版 | 浪飞IT小栈</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="前后端技术分享">
    <meta name="keywords" content="前端博客,后端博客,人工智能,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown,java,Spring,Springboot,Redis,mysql">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.ada71c49.css" as="style"><link rel="preload" href="/assets/js/app.a2a00aa5.js" as="script"><link rel="preload" href="/assets/js/2.256f807a.js" as="script"><link rel="preload" href="/assets/js/65.6afc33db.js" as="script"><link rel="prefetch" href="/assets/js/10.ab144fe3.js"><link rel="prefetch" href="/assets/js/11.062e0879.js"><link rel="prefetch" href="/assets/js/12.f9c60882.js"><link rel="prefetch" href="/assets/js/13.0a6ebfcf.js"><link rel="prefetch" href="/assets/js/14.03fc6f12.js"><link rel="prefetch" href="/assets/js/15.19dbf9fd.js"><link rel="prefetch" href="/assets/js/16.6e68160b.js"><link rel="prefetch" href="/assets/js/17.1d678834.js"><link rel="prefetch" href="/assets/js/18.4536fd5c.js"><link rel="prefetch" href="/assets/js/19.9c1b65df.js"><link rel="prefetch" href="/assets/js/20.c5f96e71.js"><link rel="prefetch" href="/assets/js/21.3f0b334e.js"><link rel="prefetch" href="/assets/js/22.55c868be.js"><link rel="prefetch" href="/assets/js/23.91286241.js"><link rel="prefetch" href="/assets/js/24.c1af1909.js"><link rel="prefetch" href="/assets/js/25.a995a755.js"><link rel="prefetch" href="/assets/js/26.abc5dea3.js"><link rel="prefetch" href="/assets/js/27.1eb62850.js"><link rel="prefetch" href="/assets/js/28.b383a871.js"><link rel="prefetch" href="/assets/js/29.088e0d73.js"><link rel="prefetch" href="/assets/js/3.cd716564.js"><link rel="prefetch" href="/assets/js/30.3ccc98d5.js"><link rel="prefetch" href="/assets/js/31.aab7cc23.js"><link rel="prefetch" href="/assets/js/32.5e16b7e6.js"><link rel="prefetch" href="/assets/js/33.4aaeb741.js"><link rel="prefetch" href="/assets/js/34.45e8e898.js"><link rel="prefetch" href="/assets/js/35.5899c97a.js"><link rel="prefetch" href="/assets/js/36.32e2e263.js"><link rel="prefetch" href="/assets/js/37.c4e27bbd.js"><link rel="prefetch" href="/assets/js/38.fe5e60d2.js"><link rel="prefetch" href="/assets/js/39.2cb0b4ee.js"><link rel="prefetch" href="/assets/js/4.edf4d5e7.js"><link rel="prefetch" href="/assets/js/40.08d5bead.js"><link rel="prefetch" href="/assets/js/41.2f80f24b.js"><link rel="prefetch" href="/assets/js/42.43a49913.js"><link rel="prefetch" href="/assets/js/43.08da7ec2.js"><link rel="prefetch" href="/assets/js/44.7c7cb8a9.js"><link rel="prefetch" href="/assets/js/45.0ddf7e7f.js"><link rel="prefetch" href="/assets/js/46.7c4609a5.js"><link rel="prefetch" href="/assets/js/47.edf3ddf8.js"><link rel="prefetch" href="/assets/js/48.569a90b9.js"><link rel="prefetch" href="/assets/js/49.fa368ac8.js"><link rel="prefetch" href="/assets/js/5.24054156.js"><link rel="prefetch" href="/assets/js/50.b9b3ea7f.js"><link rel="prefetch" href="/assets/js/51.a2ebf0fe.js"><link rel="prefetch" href="/assets/js/52.31f02238.js"><link rel="prefetch" href="/assets/js/53.4110ef1e.js"><link rel="prefetch" href="/assets/js/54.dab741c7.js"><link rel="prefetch" href="/assets/js/55.f27984e9.js"><link rel="prefetch" href="/assets/js/56.bd4c1a8e.js"><link rel="prefetch" href="/assets/js/57.375d40cb.js"><link rel="prefetch" href="/assets/js/58.932e3864.js"><link rel="prefetch" href="/assets/js/59.e657be1b.js"><link rel="prefetch" href="/assets/js/6.b259c061.js"><link rel="prefetch" href="/assets/js/60.88d94274.js"><link rel="prefetch" href="/assets/js/61.fa71d884.js"><link rel="prefetch" href="/assets/js/62.a9d3b3b7.js"><link rel="prefetch" href="/assets/js/63.f849fe75.js"><link rel="prefetch" href="/assets/js/64.1770f7a9.js"><link rel="prefetch" href="/assets/js/66.799f2eb4.js"><link rel="prefetch" href="/assets/js/67.f36b2f7d.js"><link rel="prefetch" href="/assets/js/68.868cd00b.js"><link rel="prefetch" href="/assets/js/69.4c29b907.js"><link rel="prefetch" href="/assets/js/7.e34ea00f.js"><link rel="prefetch" href="/assets/js/70.1b993ed4.js"><link rel="prefetch" href="/assets/js/71.e16ad4f9.js"><link rel="prefetch" href="/assets/js/72.627505e6.js"><link rel="prefetch" href="/assets/js/73.32768e14.js"><link rel="prefetch" href="/assets/js/74.968a580d.js"><link rel="prefetch" href="/assets/js/75.42d5af3d.js"><link rel="prefetch" href="/assets/js/76.19a69d31.js"><link rel="prefetch" href="/assets/js/77.cf627a78.js"><link rel="prefetch" href="/assets/js/78.07177880.js"><link rel="prefetch" href="/assets/js/8.c4dd00ce.js"><link rel="prefetch" href="/assets/js/9.0ff73be2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ada71c49.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="浪飞IT小栈" class="logo"> <span class="site-name can-hide">浪飞IT小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/avatar.jpg"> <div class="blogger-info"><h3>浪飞yes</h3> <span>无法简单的人儿~</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开篇</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础语法</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>面向对象</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>常用类</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础高级</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端技术</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>热门框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前后端分离</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>权限控制</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>NoSQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>微服务</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>消息中间件</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>脚手架</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/e4621d/" aria-current="page" class="active sidebar-link">脚手架-RuoYi-Vue 前后端分离版</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#一、今日学习内容与目标" class="sidebar-link">一、今日学习内容与目标</a></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#二、如何学习" class="sidebar-link">二、如何学习</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_2-1-项目阶段目标" class="sidebar-link">2.1 项目阶段目标</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_2-2-项目学习方法" class="sidebar-link">2.2 项目学习方法</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_2-3-做作业的方法" class="sidebar-link">2.3 做作业的方法</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#三、技术选型" class="sidebar-link">三、技术选型</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_3-1-脚手架" class="sidebar-link">3.1 脚手架</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_3-2-技术选型" class="sidebar-link">3.2 技术选型</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#四、ruoyi介绍" class="sidebar-link">四、RuoYi介绍</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_4-1-模块介绍" class="sidebar-link">4.1 模块介绍</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_4-2-项目启动" class="sidebar-link">4.2 项目启动</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_4-3-常见-maven-问题" class="sidebar-link">4.3 常见 Maven 问题</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_4-4-熟悉代码" class="sidebar-link">4.4 熟悉代码</a></li><li class="sidebar-sub-header level4"><a href="/pages/e4621d/#_4-4-1-代码结构" class="sidebar-link">4.4.1 代码结构</a></li><li class="sidebar-sub-header level4"><a href="/pages/e4621d/#_4-4-2-熟悉表结构" class="sidebar-link">4.4.2 熟悉表结构</a></li><li class="sidebar-sub-header level4"><a href="/pages/e4621d/#_4-4-3-熟悉项目配置" class="sidebar-link">4.4.3 熟悉项目配置</a></li><li class="sidebar-sub-header level4"><a href="/pages/e4621d/#_4-4-4-熟悉返回值" class="sidebar-link">4.4.4 熟悉返回值</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#五、岗位crud" class="sidebar-link">五、岗位CRUD</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_5-1-岗位列表" class="sidebar-link">5.1 岗位列表</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_5-2-岗位新增" class="sidebar-link">5.2 岗位新增</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_5-3-岗位修改" class="sidebar-link">5.3 岗位修改</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_5-4-岗位删除" class="sidebar-link">5.4 岗位删除</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_5-5-excel-导出功能-poi" class="sidebar-link">5.5 Excel 导出功能-POI</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#六、客户crud" class="sidebar-link">六、客户CRUD</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_6-1-使用mybatis-generator-实现" class="sidebar-link">6.1 使用mybatis-generator 实现</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_6-2-使用代码生成器生成" class="sidebar-link">6.2 使用代码生成器生成</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#七、数据字典" class="sidebar-link">七、数据字典</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_7-1-概念" class="sidebar-link">7.1 概念</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_7-2-数据字典表" class="sidebar-link">7.2 数据字典表</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_7-3-字典界面" class="sidebar-link">7.3 字典界面</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_7-4-页面使用" class="sidebar-link">7.4 页面使用</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#八、认证和授权" class="sidebar-link">八、认证和授权</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_8-1-认证" class="sidebar-link">8.1 认证</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_8-2-授权" class="sidebar-link">8.2 授权</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#九、其他" class="sidebar-link">九、其他</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_9-1-个人中心" class="sidebar-link">9.1 个人中心</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_9-2-切换主题" class="sidebar-link">9.2 切换主题</a></li><li class="sidebar-sub-header level3"><a href="/pages/e4621d/#_9-3-切换菜单" class="sidebar-link">9.3 切换菜单</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/e4621d/#十、小结与作业" class="sidebar-link">十、小结与作业</a></li></ul></li><li><a href="/pages/eed55d/" class="sidebar-link">脚手架-RuoYi-Cloud 微服务版</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>技术增值</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=Java%E9%80%9F%E9%80%9A" title="分类" data-v-06225672>Java速通</a></li><li data-v-06225672><a href="/categories/?category=%E8%84%9A%E6%89%8B%E6%9E%B6" title="分类" data-v-06225672>脚手架</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/langfeiyes" target="_blank" title="作者" class="beLink" data-v-06225672>langfeiyes</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-03-12</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">脚手架-RuoYi-Vue 前后端分离版<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="脚手架-ruoyi-vue-前后端分离版"><a href="#脚手架-ruoyi-vue-前后端分离版" class="header-anchor">#</a> 脚手架-RuoYi-Vue 前后端分离版</h1> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20240312110246754.png" alt=""></p> <h2 id="一、今日学习内容与目标"><a href="#一、今日学习内容与目标" class="header-anchor">#</a> 一、今日学习内容与目标</h2> <ul><li>掌握学项目方法</li> <li>了解若依项目模块</li> <li>掌握若依项目基本操作</li> <li>掌握基于若依二次开发</li> <li>掌握若依认证与授权</li> <li>掌握若依其他操作</li></ul> <h2 id="二、如何学习"><a href="#二、如何学习" class="header-anchor">#</a> 二、如何学习</h2> <h3 id="_2-1-项目阶段目标"><a href="#_2-1-项目阶段目标" class="header-anchor">#</a> 2.1 项目阶段目标</h3> <ol><li>本项目的重点是熟悉企业真实项目的开发流程，对实际项目开发有一个较为深刻的理解</li> <li>掌握项目中的一些重要的框架/第三方工具，比如SpringBoot，MyBatis，vue2，ElementUi等技术的使用</li> <li>锻炼自主思考能力，需求分析能力，解决bug的能力</li></ol> <h3 id="_2-2-项目学习方法"><a href="#_2-2-项目学习方法" class="header-anchor">#</a> 2.2 项目学习方法</h3> <ol><li><p>学习和理解项目中的相关业务流程，学会自己去阅读文档，进行需求分析，画图，并使用代码实现需求</p></li> <li><p>在学习的时候，不要纠结于细节的代码实现，要从更大的范围去理解一个项目/产品的设计和开发过程</p></li></ol> <h3 id="_2-3-做作业的方法"><a href="#_2-3-做作业的方法" class="header-anchor">#</a> 2.3 做作业的方法</h3> <ol><li>上课做笔记/截图，粗略版本，下课后补充完整，上课若有不理解的先记录问题，下课必须解决</li> <li>必须做到的是，写代码的时候要先自己思考和梳理， 需求是什么? 实现步骤是什么? 如何通过代码来实现功能?写代码前必须思考，并在文档中列出来</li> <li>如果没有思路， 就打开需求文档/上课笔记/课件/截图/回顾和理解 , 如果实在理解不了才去看视频 , 理解后把资料的窗口关闭 , 自己重新思考如何实现 , 直到自己能把步骤梳理出来，再开始写代码</li> <li>遇到问题，先自己解决 &gt; 不行找百度查询 &gt; 再不行找同学/老师帮助，千万不要养成依赖别人的习惯，这样以后工作了是很难独立生存的</li> <li>当天的作业第一遍做完后，写第二遍，第二遍的目标是独立完成，当天写不完那就自习或休息天时再继续写，自习或休息天还要把总结补上</li> <li>如果有的同学，作业实在是做得太晚，第一遍都做不完，给讲师或班主任发个微信，申请延交作业，并说明什么原因导致，需要在自习把进度赶上来，如果连续3次都延迟，说明问题较严重，要主动找老师沟通</li></ol> <h2 id="三、技术选型"><a href="#三、技术选型" class="header-anchor">#</a> 三、技术选型</h2> <h3 id="_3-1-脚手架"><a href="#_3-1-脚手架" class="header-anchor">#</a> 3.1 脚手架</h3> <p>脚手架是为了保证各施工过程顺利进行而搭设的工作平台。按搭设的位置分为外脚手架、里脚手架；按材料不同可分为木脚手架、竹脚手架、钢管脚手架；按构造形式分为立杆式脚手架、桥式脚手架、门式脚手架、悬吊式脚手架、挂式脚手架、挑式脚手架、爬式脚手架。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007124706542.png" alt=""></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007124822828.png" alt=""></p> <p><strong>那么编程界的脚手架又是啥</strong></p> <p><strong>这里是stackoverflow上的一个回答</strong>：</p> <p>Scaffolding is a meta-programming method of building database-backed software applications. It is a technique supported by some model-view-controller frameworks, in which the programmer may write a specification that describes how the application database may be used. The compiler uses this specification to generate code that the application can use to create, read, update and delete database entries, effectively treating the template as a &quot;scaffold&quot; on which to build a more powerful application.</p> <p>“脚手架”是一种元编程的方法，用于构建基于数据库的应用。许多MVC框架都有运用这种思想。程序员编写一份specification（规格说明书），来描述怎样去使用数据库；而由（脚手架的）编译器来根据这份specification生成相应的代码，进行增、删、改、查数据库的操作。我们把这种模式称为&quot;脚手架&quot;，在脚手架上面去更高效的建造出强大的应用！</p> <p><strong>大白话的讲</strong>：在项目最开始的时候，脚手架工具已经准备好一份代码，里面包含通用的基础功能，比如用户登录，权限控制，菜单管理，系统管理等，程序员只需要在这基础上进行业务开发。</p> <p>项目一我们就是在脚手架(car_o2o)的基础上进行需求开发</p> <h3 id="_3-2-技术选型"><a href="#_3-2-技术选型" class="header-anchor">#</a> 3.2 技术选型</h3> <p>在项目开发前，需要对技术方案先做方向性的评估。在投资有限、硬件资源有限的条件下，为了满足需求，需要进行技术方案选型、技术点使用范围进行分析。也就是需要选择哪种类型脚手架(包含哪些技术的脚手架)</p> <p><strong>常见的技术选型度量点：</strong></p> <p>（1）<strong>快速开发</strong></p> <p>（2）<strong>学习成本低</strong></p> <p>（3）<strong>技术成熟度</strong></p> <p>（4）稳定性</p> <p>（5）性能</p> <p><strong>当前项目技术选型:</strong></p> <p>主框架：Spring Boot +Spring Framework + SpringSecurity</p> <p>持久层：Apache MyBatis +Hibernate Validation +Alibaba Druid</p> <p>视图层：Vue + ElementUi</p> <p>其他： Activiti7 +POI+ Redis</p> <h2 id="四、ruoyi介绍"><a href="#四、ruoyi介绍" class="header-anchor">#</a> 四、RuoYi介绍</h2> <p>若依框架，官网：http://www.ruoyi.vip/</p> <p>源码:https://gitee.com/y_project/RuoYi-Vue</p> <p>文档:https://doc.ruoyi.vip/ruoyi-vue/</p> <p>当前我们的学习目标是能快速掌握RuoYi脚手架快速上手。</p> <h3 id="_4-1-模块介绍"><a href="#_4-1-模块介绍" class="header-anchor">#</a> 4.1 模块介绍</h3> <p>RuoYi脚手架大体分为5个模块：首页，系统管理，系统监控，系统工具，RuoYi 官网 ，个人中心</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20231020143006869.png" alt=""></p> <p><strong>系统管理</strong>：管理系统各项配置</p> <p>​	核心模块：用户管理，角色管理，菜单管理，部门管理，岗位管理，字典管理，参数设置，通知公告</p> <p><strong>系统监控</strong>：系统运行过程中数据监控</p> <p>​	核心模块：数据监控，服务监控，日志监控，缓存监控，在线用户，缓存列表</p> <p><strong>系统工具</strong>：代码生成器</p> <p>​	核心模块：表单构建，代码生成，系统接口</p> <p><strong>RuoYi 官网</strong>：跳转到官网</p> <p><strong>个人中心</strong>：个人偏好设置</p> <p>​	核心模块：个人中心，切换主题，切换菜单</p> <h3 id="_4-2-项目启动"><a href="#_4-2-项目启动" class="header-anchor">#</a> 4.2 项目启动</h3> <p>操作步骤：</p> <div class="language-tex line-numbers-mode"><pre class="language-tex"><code>1》 从官网把 RuoYi 项目下载下载

2》 通过 idea 导入到进去

3》 创建数据库 ry-vue，把sql 文件拖拽进去

4》 修改application-druid.yml 连接四要素信息

5》启动ruoyi-admin 中的启动类RuoYiAppliacation

6》启动前端项目

   6.1》进入到 ruoyi-ui 的目录中执行 npm install 安装依赖

   6.2》 执行 npm  run dev 启动前端项目
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="_4-3-常见-maven-问题"><a href="#_4-3-常见-maven-问题" class="header-anchor">#</a> 4.3 常见 Maven 问题</h3> <p>进入到公司第一天就如刚才操作一样，把项目下载到本地然后导入到 idea 进行启动， 但是在导入的过程中最常见的一个问题就是 maven 的问题，也是最容易把大家搞崩溃的问题。</p> <p>情况 1： 公司有私服依赖下载不下来
解决：和同事要一份 settings.xml 文件把本地覆盖掉</p> <p>情况 2：网络原因依赖下载一半，自己手动取消了，在进行下载下载不了
解决：找到本地仓库所在位置删除然后在刷新</p> <p>情况 3：idea无法识别出来项目是一个 maven 项目结构
解决： 双加 shift -&gt; 搜索maven -&gt; 找到 add maven project-&gt; 选中项目的 pom 文件</p> <h3 id="_4-4-熟悉代码"><a href="#_4-4-熟悉代码" class="header-anchor">#</a> 4.4 熟悉代码</h3> <p>在学习项目的过程中我们不仅仅要学会分析需求写代码， 也要学会看代码，学会把别人的代码看懂然后转换成自己的代码。</p> <h4 id="_4-4-1-代码结构"><a href="#_4-4-1-代码结构" class="header-anchor">#</a> 4.4.1 代码结构</h4> <p>Ruoyi-admin:  web 模块存放 controller</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117112132241.png" alt=""></em></p> <p>Ruoyi—common: 公共模块存放工具类</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117112243980.png" alt=""></em></p> <p>Ruoyi-framework：框架模块存放一些第三方框架代码和配置</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117112353580.png" alt=""></em></p> <p>Ruoyi-generator: 代码生成器模块</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117112518667.png" alt=""></em></p> <p>Ruoyi-quartz: 定时任务模块</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117112557727.png" alt=""></em></p> <p>Ruoyi-system：系统模块存放 domain，mapper，service</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117112656484.png" alt=""></em></p> <p>Ruoyi-ui：前端项目</p> <p><strong>思考两个个问题</strong></p> <ul><li>好好一个项目为什么要拆碎？--组件/模块化开发</li> <li>为什么拆碎了能合起来？--pom.xml</li></ul> <p>先从pom.xml文件中了解不同组件关系</p> <p>ruoYi-admin -pom：</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token comment">&lt;!-- 核心模块--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.ruoyi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>ruoyi-framework<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>

<span class="token comment">&lt;!-- 定时任务--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.ruoyi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>ruoyi-quartz<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>

<span class="token comment">&lt;!-- 代码生成--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.ruoyi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>ruoyi-generator<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>ruoYi-framework-pom:</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token comment">&lt;!-- 系统模块--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.ruoyi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>ruoyi-system<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>Ruoyi-generator-pom:</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token comment">&lt;!-- 通用工具--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.ruoyi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>ruoyi-common<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>Ruoyi-system-pom:</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token comment">&lt;!-- 通用工具--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.ruoyi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>ruoyi-common<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><blockquote><p>所以我们得出结论，虽然是分模块开发的， 但是最终他通过 pom 文件把这些模块的代码都聚集在了 ruoyi-admin中</p></blockquote> <h4 id="_4-4-2-熟悉表结构"><a href="#_4-4-2-熟悉表结构" class="header-anchor">#</a> 4.4.2 熟悉表结构</h4> <p>打开数据库，观察到表一共有 19 张表，我们不需要搞清楚每一个字段都是干什么的那样工作量太大了也没有必要， 我们只需要大概知道每一张表对应着是存什么数据就可以了。</p> <p>表介绍图：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117143622177.png" alt=""></p> <h4 id="_4-4-3-熟悉项目配置"><a href="#_4-4-3-熟悉项目配置" class="header-anchor">#</a> 4.4.3 熟悉项目配置</h4> <p>整个项目配置文件都在 ruoyi-admin 的 resources 中</p> <p>resources:</p> <ul><li><p>i18 n            -》 处理国际化 -  本项目没有做国际化</p></li> <li><p>META-INF  -》 此文件包含有关 JAR 内容的元数据 （不需要管）</p></li> <li><p>mybatis       -》 存放 mybatis 配置信息</p></li> <li><p>application.yml              -》存放项目的所有配置信息</p></li> <li><p>Application-druid.yml  -》 存放数据库连接信息</p></li> <li><p>banner.txt                        -》 存放启动时候的 baner 图标信息</p></li> <li><p>Logback.xml                    -》 存放项目中的日志配置信息</p></li></ul> <h4 id="_4-4-4-熟悉返回值"><a href="#_4-4-4-熟悉返回值" class="header-anchor">#</a> 4.4.4 熟悉返回值</h4> <p>我们本次RuoYi脚手架使用的是前后端分离的版本，后端接口依旧是返回 json 格式数据， 但是他这里和我们之前RBAC的返回是有一些区别，他一共有 3 中返回值，<strong>TableDataInfo</strong>(分页列表)、<strong>void</strong>(导出/下载)、<strong>AjaxResult</strong>(基本添加/编辑/单个查询/删除)。----&gt;json</p> <p>TableDataInfo：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TableDataInfo</span> <span class="token keyword">implements</span> <span class="token class-name">Serializable</span>
<span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token keyword">long</span> serialVersionUID <span class="token operator">=</span> <span class="token number">1L</span><span class="token punctuation">;</span>

    <span class="token comment">/** 总记录数 */</span>
    <span class="token keyword">private</span> <span class="token keyword">long</span> total<span class="token punctuation">;</span>

    <span class="token comment">/** 列表数据 */</span>
    <span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> rows<span class="token punctuation">;</span>

    <span class="token comment">/** 消息状态码 */</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span> code<span class="token punctuation">;</span>

    <span class="token comment">/** 消息内容 */</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> msg<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 表格数据对象
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">TableDataInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 分页
     * 
     * @param list 列表数据
     * @param total 总记录数
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">TableDataInfo</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> list<span class="token punctuation">,</span> <span class="token keyword">int</span> total<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>rows <span class="token operator">=</span> list<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>total <span class="token operator">=</span> total<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br></div></div><p>AjaxResult:</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AjaxResult</span> <span class="token keyword">extends</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span>
<span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token keyword">long</span> serialVersionUID <span class="token operator">=</span> <span class="token number">1L</span><span class="token punctuation">;</span>

    <span class="token comment">/** 状态码 */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> <span class="token constant">CODE_TAG</span> <span class="token operator">=</span> <span class="token string">&quot;code&quot;</span><span class="token punctuation">;</span>

    <span class="token comment">/** 返回内容 */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> <span class="token constant">MSG_TAG</span> <span class="token operator">=</span> <span class="token string">&quot;msg&quot;</span><span class="token punctuation">;</span>

    <span class="token comment">/** 数据对象 */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> <span class="token constant">DATA_TAG</span> <span class="token operator">=</span> <span class="token string">&quot;data&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="五、岗位crud"><a href="#五、岗位crud" class="header-anchor">#</a> 五、岗位CRUD</h2> <p>由于篇幅所限，不对系统做全貌介绍，这里挑选几个核心模块详细介绍，其他模块同理可得。</p> <p><strong>思考一个问题：怎么解读一个项目业务模块？</strong></p> <p><strong>业务前提</strong>：知道它在做什么---岗位crud</p> <p><strong>技术前提</strong>：前端vue--基本操作必须会   后端ssm--必须会</p> <p><strong>开发技巧</strong>： 前端会F12，后端会debug</p> <p><strong>常规项目特点</strong>：管理类项目特点--先页面，后接口；经典厂字形布局</p> <p>web项目组件解读技巧：</p> <p><strong>主线</strong>：发起请求---接收请求----处理请求----响应请求</p> <p>详细展开：</p> <p>1&gt;客户端怎么发起请求(关注：请求url/请求方式/请求头/请求参数)</p> <p>2&gt;接口接收请求(关注：接口定义/参数接收/参数封装/参数校验/)</p> <p>3&gt;接口处理请求(关注：业务逻辑实现)</p> <p>4&gt;接口响应请求(关注：响应数据类型/数据格式/响应头)</p> <p><strong>强调：走流程时，一定要结合所掌握的技术合理推演。</strong></p> <p><strong>案例：岗位CRUD</strong></p> <h3 id="_5-1-岗位列表"><a href="#_5-1-岗位列表" class="header-anchor">#</a> 5.1 岗位列表</h3> <p>页面显示效果：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118143255228.png" alt=""></p> <p>请求路径：http://localhost:1024/dev-api/system/post/list?pageNum=1&amp;pageSize=10</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118143435509.png" alt=""></p> <p>请求参数：</p> <p><img src="images/image-20221118144414094.png" alt="image-20221118144414094"></p> <p>返回值：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span><span class="token property">&quot;total&quot;</span><span class="token operator">:</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token property">&quot;rows&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token property">&quot;searchValue&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;createBy&quot;</span><span class="token operator">:</span><span class="token string">&quot;admin&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;createTime&quot;</span><span class="token operator">:</span><span class="token string">&quot;2022-11-17 10:58:15&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;updateBy&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;updateTime&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;remark&quot;</span><span class="token operator">:</span><span class="token string">&quot;&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;params&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token property">&quot;postId&quot;</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token property">&quot;postCode&quot;</span><span class="token operator">:</span><span class="token string">&quot;ceo&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postName&quot;</span><span class="token operator">:</span><span class="token string">&quot;董事长&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postSort&quot;</span><span class="token operator">:</span><span class="token string">&quot;1&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;status&quot;</span><span class="token operator">:</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;flag&quot;</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{</span><span class="token property">&quot;searchValue&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;createBy&quot;</span><span class="token operator">:</span><span class="token string">&quot;admin&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;createTime&quot;</span><span class="token operator">:</span><span class="token string">&quot;2022-11-17 10:58:15&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;updateBy&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;updateTime&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;remark&quot;</span><span class="token operator">:</span><span class="token string">&quot;&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;params&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token property">&quot;postId&quot;</span><span class="token operator">:</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token property">&quot;postCode&quot;</span><span class="token operator">:</span><span class="token string">&quot;se&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postName&quot;</span><span class="token operator">:</span><span class="token string">&quot;项目经理&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postSort&quot;</span><span class="token operator">:</span><span class="token string">&quot;2&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;status&quot;</span><span class="token operator">:</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;flag&quot;</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{</span><span class="token property">&quot;searchValue&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;createBy&quot;</span><span class="token operator">:</span><span class="token string">&quot;admin&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;createTime&quot;</span><span class="token operator">:</span><span class="token string">&quot;2022-11-17 10:58:15&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;updateBy&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;updateTime&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;remark&quot;</span><span class="token operator">:</span><span class="token string">&quot;&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;params&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token property">&quot;postId&quot;</span><span class="token operator">:</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token property">&quot;postCode&quot;</span><span class="token operator">:</span><span class="token string">&quot;hr&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postName&quot;</span><span class="token operator">:</span><span class="token string">&quot;人力资源&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postSort&quot;</span><span class="token operator">:</span><span class="token string">&quot;3&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;status&quot;</span><span class="token operator">:</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;flag&quot;</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{</span><span class="token property">&quot;searchValue&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;createBy&quot;</span><span class="token operator">:</span><span class="token string">&quot;admin&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;createTime&quot;</span><span class="token operator">:</span><span class="token string">&quot;2022-11-17 10:58:15&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;updateBy&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;updateTime&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;remark&quot;</span><span class="token operator">:</span><span class="token string">&quot;&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;params&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token property">&quot;postId&quot;</span><span class="token operator">:</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token property">&quot;postCode&quot;</span><span class="token operator">:</span><span class="token string">&quot;user&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postName&quot;</span><span class="token operator">:</span><span class="token string">&quot;普通员工&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postSort&quot;</span><span class="token operator">:</span><span class="token string">&quot;4&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;status&quot;</span><span class="token operator">:</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;flag&quot;</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{</span><span class="token property">&quot;searchValue&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;createBy&quot;</span><span class="token operator">:</span><span class="token string">&quot;admin&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;createTime&quot;</span><span class="token operator">:</span><span class="token string">&quot;2022-11-18 14:42:38&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;updateBy&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;updateTime&quot;</span><span class="token operator">:</span><span class="token null keyword">null</span><span class="token punctuation">,</span><span class="token property">&quot;remark&quot;</span><span class="token operator">:</span><span class="token string">&quot;123&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;params&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token property">&quot;postId&quot;</span><span class="token operator">:</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token property">&quot;postCode&quot;</span><span class="token operator">:</span><span class="token string">&quot;123&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postName&quot;</span><span class="token operator">:</span><span class="token string">&quot;123&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;postSort&quot;</span><span class="token operator">:</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;status&quot;</span><span class="token operator">:</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span><span class="token property">&quot;flag&quot;</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token property">&quot;code&quot;</span><span class="token operator">:</span><span class="token number">200</span><span class="token punctuation">,</span><span class="token property">&quot;msg&quot;</span><span class="token operator">:</span><span class="token string">&quot;查询成功&quot;</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>结合之前学的springmvc框架路径分析：</p> <p>1：system/post是映射路径前缀，一般设置下controller中</p> <p>2：路径中post可以推测是岗位的意思，进而猜测controller名字是： SysPostController</p> <p>3：list猜测是后端映射方法路径</p> <p>围绕这个思路取找到PostController里面的listPage映射方法</p> <p>cn/wolfcode/car/base/web/controller/system/SysPostController</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * 岗位控制器
 */</span>
<span class="token annotation punctuation">@Controller</span>
<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">&quot;system/post&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PostController</span> <span class="token punctuation">{</span>
    
    <span class="token comment">/**
     * 获取岗位列表
     */</span>
    <span class="token annotation punctuation">@PreAuthorize</span><span class="token punctuation">(</span><span class="token string">&quot;@ss.hasPermi('system:post:list')&quot;</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/list&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">TableDataInfo</span> <span class="token function">list</span><span class="token punctuation">(</span><span class="token class-name">SysPost</span> post<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token function">startPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SysPost</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> postService<span class="token punctuation">.</span><span class="token function">selectPostList</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token function">getDataTable</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>startPage():</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">startPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token class-name">PageDomain</span> pageDomain <span class="token operator">=</span> <span class="token class-name">TableSupport</span><span class="token punctuation">.</span><span class="token function">buildPageRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Integer</span> pageNum <span class="token operator">=</span> pageDomain<span class="token punctuation">.</span><span class="token function">getPageNum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Integer</span> pageSize <span class="token operator">=</span> pageDomain<span class="token punctuation">.</span><span class="token function">getPageSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> orderBy <span class="token operator">=</span> <span class="token class-name">SqlUtil</span><span class="token punctuation">.</span><span class="token function">escapeOrderBySql</span><span class="token punctuation">(</span>pageDomain<span class="token punctuation">.</span><span class="token function">getOrderBy</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Boolean</span> reasonable <span class="token operator">=</span> pageDomain<span class="token punctuation">.</span><span class="token function">getReasonable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">PageHelper</span><span class="token punctuation">.</span><span class="token function">startPage</span><span class="token punctuation">(</span>pageNum<span class="token punctuation">,</span> pageSize<span class="token punctuation">,</span> orderBy<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setReasonable</span><span class="token punctuation">(</span>reasonable<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>实现思路：</p> <p>1：调用 startPage()，把当前页和每页显示数据设置到 PageHelper 当中</p> <p>2：调用 postService查询分页数据</p> <p>3：把查询数据封装到奥 TableDataInfo 中</p> <h3 id="_5-2-岗位新增"><a href="#_5-2-岗位新增" class="header-anchor">#</a> 5.2 岗位新增</h3> <p>点击新增按钮弹出模块框</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118144200644.png" alt=""></p> <p>点击确定发送请求：http://localhost:1024/dev-api/system/post</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118144304000.png" alt=""></p> <p>请求参数：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118144319685.png" alt=""></p> <p>返回值：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118144333129.png" alt=""></p> <p>后台代码：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * 新增岗位
 */</span>
<span class="token annotation punctuation">@PreAuthorize</span><span class="token punctuation">(</span><span class="token string">&quot;@ss.hasPermi('system:post:add')&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Log</span><span class="token punctuation">(</span>title <span class="token operator">=</span> <span class="token string">&quot;岗位管理&quot;</span><span class="token punctuation">,</span> businessType <span class="token operator">=</span> <span class="token class-name">BusinessType</span><span class="token punctuation">.</span><span class="token constant">INSERT</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@PostMapping</span>
<span class="token keyword">public</span> <span class="token class-name">AjaxResult</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token annotation punctuation">@Validated</span> <span class="token annotation punctuation">@RequestBody</span> <span class="token class-name">SysPost</span> post<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">UserConstants</span><span class="token punctuation">.</span><span class="token constant">NOT_UNIQUE</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">checkPostNameUnique</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">AjaxResult</span><span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;新增岗位'&quot;</span> <span class="token operator">+</span> post<span class="token punctuation">.</span><span class="token function">getPostName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;'失败，岗位名称已存在&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">UserConstants</span><span class="token punctuation">.</span><span class="token constant">NOT_UNIQUE</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">checkPostCodeUnique</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">AjaxResult</span><span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;新增岗位'&quot;</span> <span class="token operator">+</span> post<span class="token punctuation">.</span><span class="token function">getPostName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;'失败，岗位编码已存在&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    post<span class="token punctuation">.</span><span class="token function">setCreateBy</span><span class="token punctuation">(</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token function">toAjax</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">insertPost</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>实现思路：</p> <p>1：检测一下数据库中是否存在这个岗位了</p> <p>2：检验岗位编码是否唯一</p> <p>3： 保存数据到 MySql 中然后返回</p> <h3 id="_5-3-岗位修改"><a href="#_5-3-岗位修改" class="header-anchor">#</a> 5.3 岗位修改</h3> <p>点击修改弹出模块框</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118145155299.png" alt=""></p> <p>点击确定发送请求：http://localhost:1024/dev-api/system/post</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118145252391.png" alt=""></p> <p>请求参数：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118145305173.png" alt=""></p> <p>返回值：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118145317443.png" alt=""></p> <p>后台代码：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * 修改岗位
 */</span>
<span class="token annotation punctuation">@PreAuthorize</span><span class="token punctuation">(</span><span class="token string">&quot;@ss.hasPermi('system:post:edit')&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Log</span><span class="token punctuation">(</span>title <span class="token operator">=</span> <span class="token string">&quot;岗位管理&quot;</span><span class="token punctuation">,</span> businessType <span class="token operator">=</span> <span class="token class-name">BusinessType</span><span class="token punctuation">.</span><span class="token constant">UPDATE</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@PutMapping</span>
<span class="token keyword">public</span> <span class="token class-name">AjaxResult</span> <span class="token function">edit</span><span class="token punctuation">(</span><span class="token annotation punctuation">@Validated</span> <span class="token annotation punctuation">@RequestBody</span> <span class="token class-name">SysPost</span> post<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">UserConstants</span><span class="token punctuation">.</span><span class="token constant">NOT_UNIQUE</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">checkPostNameUnique</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">AjaxResult</span><span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;修改岗位'&quot;</span> <span class="token operator">+</span> post<span class="token punctuation">.</span><span class="token function">getPostName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;'失败，岗位名称已存在&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">UserConstants</span><span class="token punctuation">.</span><span class="token constant">NOT_UNIQUE</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">checkPostCodeUnique</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">AjaxResult</span><span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;修改岗位'&quot;</span> <span class="token operator">+</span> post<span class="token punctuation">.</span><span class="token function">getPostName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;'失败，岗位编码已存在&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    post<span class="token punctuation">.</span><span class="token function">setUpdateBy</span><span class="token punctuation">(</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token function">toAjax</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">updatePost</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>实现思路：</p> <p>1：安全性校验</p> <p>2：修改数据</p> <h3 id="_5-4-岗位删除"><a href="#_5-4-岗位删除" class="header-anchor">#</a> 5.4 岗位删除</h3> <p>点击删除弹出确定框</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub//image-20221118145811501.png" alt="image-20221118145811501"></p> <p>点击确定发送请求：http://localhost:1024/dev-api/system/post/5</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118145942558.png" alt=""></p> <p>请求参数： id</p> <p>请求返回值:</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118145951722.png" alt=""></p> <p>后台代码：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * 删除岗位
 */</span>
<span class="token annotation punctuation">@PreAuthorize</span><span class="token punctuation">(</span><span class="token string">&quot;@ss.hasPermi('system:post:remove')&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Log</span><span class="token punctuation">(</span>title <span class="token operator">=</span> <span class="token string">&quot;岗位管理&quot;</span><span class="token punctuation">,</span> businessType <span class="token operator">=</span> <span class="token class-name">BusinessType</span><span class="token punctuation">.</span><span class="token constant">DELETE</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@DeleteMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/{postIds}&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">AjaxResult</span> <span class="token function">remove</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span> <span class="token class-name">Long</span><span class="token punctuation">[</span><span class="token punctuation">]</span> postIds<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">toAjax</span><span class="token punctuation">(</span>postService<span class="token punctuation">.</span><span class="token function">deletePostByIds</span><span class="token punctuation">(</span>postIds<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_5-5-excel-导出功能-poi"><a href="#_5-5-excel-导出功能-poi" class="header-anchor">#</a> 5.5 Excel 导出功能-POI</h3> <p>前台点击按钮直接把数据库中的数据以 excel 导出到本地</p> <p>后台代码：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Log</span><span class="token punctuation">(</span>title <span class="token operator">=</span> <span class="token string">&quot;岗位管理&quot;</span><span class="token punctuation">,</span> businessType <span class="token operator">=</span> <span class="token class-name">BusinessType</span><span class="token punctuation">.</span><span class="token constant">EXPORT</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@PreAuthorize</span><span class="token punctuation">(</span><span class="token string">&quot;@ss.hasPermi('system:post:export')&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@PostMapping</span><span class="token punctuation">(</span><span class="token string">&quot;/export&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">export</span><span class="token punctuation">(</span><span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">,</span> <span class="token class-name">SysPost</span> post<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SysPost</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> postService<span class="token punctuation">.</span><span class="token function">selectPostList</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">ExcelUtil</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SysPost</span><span class="token punctuation">&gt;</span></span> util <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelUtil</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SysPost</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token class-name">SysPost</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    util<span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span>response<span class="token punctuation">,</span> list<span class="token punctuation">,</span> <span class="token string">&quot;岗位数据&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>实体类上需要贴注解：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SysPost</span> <span class="token keyword">extends</span> <span class="token class-name">BaseEntity</span>
<span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token keyword">long</span> serialVersionUID <span class="token operator">=</span> <span class="token number">1L</span><span class="token punctuation">;</span>

    <span class="token comment">/** 岗位序号 */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;岗位序号&quot;</span><span class="token punctuation">,</span> cellType <span class="token operator">=</span> <span class="token class-name">ColumnType</span><span class="token punctuation">.</span><span class="token constant">NUMERIC</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Long</span> postId<span class="token punctuation">;</span>

    <span class="token comment">/** 岗位编码 */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;岗位编码&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> postCode<span class="token punctuation">;</span>

    <span class="token comment">/** 岗位名称 */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;岗位名称&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> postName<span class="token punctuation">;</span>

    <span class="token comment">/** 岗位排序 */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;岗位排序&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> postSort<span class="token punctuation">;</span>

    <span class="token comment">/** 状态（0正常 1停用） */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">&quot;状态&quot;</span><span class="token punctuation">,</span> readConverterExp <span class="token operator">=</span> <span class="token string">&quot;0=正常,1=停用&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> status<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h2 id="六、客户crud"><a href="#六、客户crud" class="header-anchor">#</a> 六、客户CRUD</h2> <p>现在已经看懂了岗位的工程， 那么我们可以参考别人的代码去完成我们自己的代码。</p> <h3 id="_6-1-使用mybatis-generator-实现"><a href="#_6-1-使用mybatis-generator-实现" class="header-anchor">#</a> 6.1 使用mybatis-generator 实现</h3> <p>1：建表-customer</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token identifier"><span class="token punctuation">`</span>customer<span class="token punctuation">`</span></span> <span class="token punctuation">(</span>
  <span class="token identifier"><span class="token punctuation">`</span>id<span class="token punctuation">`</span></span> <span class="token keyword">bigint</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'id'</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>name<span class="token punctuation">`</span></span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'名称'</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>phone<span class="token punctuation">`</span></span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'手机号'</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>age<span class="token punctuation">`</span></span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'年龄'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token identifier"><span class="token punctuation">`</span>id<span class="token punctuation">`</span></span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span>  <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'客户表'</span><span class="token punctuation">;</span>

<span class="token keyword">SET</span> FOREIGN_KEY_CHECKS <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>2：拷贝配置文件generatorConfig.xml 到 ruoyi-system中</p> <p>​	在 pom 文件中加入依赖</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>build</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugins</span><span class="token punctuation">&gt;</span></span>
            <span class="token comment">&lt;!-- MyBatis 的 generator 插件--&gt;</span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugin</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.mybatis.generator<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>mybatis-generator-maven-plugin<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>1.3.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>configuration</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>verbose</span><span class="token punctuation">&gt;</span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>verbose</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>overwrite</span><span class="token punctuation">&gt;</span></span>false<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>overwrite</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>configuration</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>mysql<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>mysql-connector-java<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>5.1.45<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugin</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugins</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>build</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><p>3：使用插件生成 domain，mapper，xml 文件</p> <p>4：添加 selectForList() 方法</p> <p>5： 拷贝 岗位的 service 和 impl 实现类 和 controller，修改成</p> <p>6：拷贝前端界面到对应界面中</p> <p>7：创建客户的菜单</p> <h3 id="_6-2-使用代码生成器生成"><a href="#_6-2-使用代码生成器生成" class="header-anchor">#</a> 6.2 使用代码生成器生成</h3> <p>系统工具》代码生成器-》导入</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118151555166.png" alt=""></p> <p>在界面中选中我们自己创建的 Customer 表</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118151711996.png" alt=""></p> <p>点击确定以后修改生成信息</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221118151744118.png" alt=""></p> <p>修改完以后点击生成，domain，mapper，service，impl，controller，界面就一键都生成好了。</p> <h2 id="七、数据字典"><a href="#七、数据字典" class="header-anchor">#</a> 七、数据字典</h2> <p><strong>背景</strong>：我们在项目中会有很多的下拉框,这些下拉框都有一个特点,就是键值对的存在.
实现下拉框方式：</p> <ul><li>界面写死-》 有硬编码问题</li> <li>给下拉框创建张表-》 要创建很多张表</li> <li>使用数据字典实现</li></ul> <h3 id="_7-1-概念"><a href="#_7-1-概念" class="header-anchor">#</a> 7.1 概念</h3> <p>**数据字典（data dictionary）**是对于数据模型中的数据对象或者项目的描述的集合，这样做有利于程序员和其他需要参考的人。分析一个用户交换的对象系统的第一步就是去辨别每一个对象，以及它与其他对象之间的关系。这个过程称为数据建模，结果产生一个对象关系图。当每个数据对象和项目都给出了一个描述性的名字之后，它的关系再进行描述（或者是成为潜在描述关系的结构中的一部分），然后再描述数据的类型（例如文本还是图像，或者是二进制数值），列出所有可能预先定义的数值，以及提供简单的文字性描述。这个集合被组织成书的形式用来参考，就叫做数据字典。</p> <p><strong>大白话</strong>：一种数据组织形式，方便使用者维护数据，管理数据。</p> <h3 id="_7-2-数据字典表"><a href="#_7-2-数据字典表" class="header-anchor">#</a> 7.2 数据字典表</h3> <p>脚手架中的数据字典组成数据结构由2张表共同维护</p> <p>sys_dict_type: 字典类型表</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117153024850.png" alt=""></p> <p>表数据：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117153045682.png" alt=""></p> <p>sys_dict_data: 字典明细表</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117153111618.png" alt=""></p> <p>表数据：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117153139033.png" alt=""></p> <h3 id="_7-3-字典界面"><a href="#_7-3-字典界面" class="header-anchor">#</a> 7.3 字典界面</h3> <p>数据字典列表</p> <p>系统管理》字典管理</p> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007205918535.png" alt=""></strong></p> <p>列表的数据是数据类型表：DictTypeController 中listPage方法</p> <p>点击操作中的列表，新开一个页签，进入到字典数据列表：DictDataController 中listPage方法</p> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007210141263.png" alt=""></strong></p> <h3 id="_7-4-页面使用"><a href="#_7-4-页面使用" class="header-anchor">#</a> 7.4 页面使用</h3> <p>数据字典具体使用主要集中在页面的下拉框控件中，比如：</p> <p>系统管理》岗位管理</p> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007210736978.png" alt=""></strong></p> <p>浏览器发送请求</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20221117155900971.png" alt=""></p> <p>在SysDicDataController 中</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * 根据字典类型查询字典数据信息
 */</span>
<span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/type/{dictType}&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">AjaxResult</span> <span class="token function">dictType</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span> <span class="token class-name">String</span> dictType<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SysDictData</span><span class="token punctuation">&gt;</span></span> data <span class="token operator">=</span> dictTypeService<span class="token punctuation">.</span><span class="token function">selectDictDataByType</span><span class="token punctuation">(</span>dictType<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">isNull</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        data <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SysDictData</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token class-name">AjaxResult</span><span class="token punctuation">.</span><span class="token function">success</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>在 SysDictDataMapper.xml中</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>select</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>selectDictDataByType<span class="token punctuation">&quot;</span></span> <span class="token attr-name">parameterType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>SysDictData<span class="token punctuation">&quot;</span></span> <span class="token attr-name">resultMap</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>SysDictDataResult<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>include</span> <span class="token attr-name">refid</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>selectDictDataVo<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span>
   where status = '0' and dict_type = #{dictType} order by dict_sort asc
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>select</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="八、认证和授权"><a href="#八、认证和授权" class="header-anchor">#</a> 八、认证和授权</h2> <p>认证和授权采用是 SpringSecurity进行操作， 基本和我们之前在 RBAC中集成的操作是差不多的，这里也是带大家去观察 RuoYi 是如何写代码的。</p> <h3 id="_8-1-认证"><a href="#_8-1-认证" class="header-anchor">#</a> 8.1 认证</h3> <p>1、导入依赖</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token comment">&lt;!-- spring security 安全认证 --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-boot-starter-security<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>2、SecurityConfig配置</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>
<span class="token annotation punctuation">@EnableGlobalMethodSecurity</span><span class="token punctuation">(</span>prePostEnabled <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span> securedEnabled <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SecurityConfig</span> <span class="token keyword">extends</span> <span class="token class-name">WebSecurityConfigurerAdapter</span>
<span class="token punctuation">{</span>
    <span class="token comment">/**
     * 自定义用户认证逻辑
     */</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">UserDetailsService</span> userDetailsService<span class="token punctuation">;</span>
    
    <span class="token comment">/**
     * 认证失败处理类
     */</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">AuthenticationEntryPointImpl</span> unauthorizedHandler<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 退出处理类
     */</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">LogoutSuccessHandlerImpl</span> logoutSuccessHandler<span class="token punctuation">;</span>

    <span class="token comment">/**
     * token认证过滤器
     */</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">JwtAuthenticationTokenFilter</span> authenticationTokenFilter<span class="token punctuation">;</span>
    
    <span class="token comment">/**
     * 跨域过滤器
     */</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">CorsFilter</span> corsFilter<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 允许匿名访问的地址
     */</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">PermitAllUrlProperties</span> permitAllUrl<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 解决 无法直接注入 AuthenticationManager
     *
     * @return
     * @throws Exception
     */</span>
    <span class="token annotation punctuation">@Bean</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">AuthenticationManager</span> <span class="token function">authenticationManagerBean</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">authenticationManagerBean</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">configure</span><span class="token punctuation">(</span><span class="token class-name">HttpSecurity</span> httpSecurity<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span>
    <span class="token punctuation">{</span>
        <span class="token comment">// 注解标记允许匿名访问的url</span>
        <span class="token class-name">ExpressionUrlAuthorizationConfigurer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">HttpSecurity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">.</span>ExpressionInterceptUrlRegistry registry <span class="token operator">=</span> httpSecurity<span class="token punctuation">.</span><span class="token function">authorizeRequests</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        permitAllUrl<span class="token punctuation">.</span><span class="token function">getUrls</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>url <span class="token operator">-&gt;</span> registry<span class="token punctuation">.</span><span class="token function">antMatchers</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">permitAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        httpSecurity
                <span class="token comment">// CSRF禁用，因为不使用session</span>
                <span class="token punctuation">.</span><span class="token function">csrf</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">disable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment">// 认证失败处理类</span>
                <span class="token punctuation">.</span><span class="token function">exceptionHandling</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">authenticationEntryPoint</span><span class="token punctuation">(</span>unauthorizedHandler<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">and</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment">// 基于token，所以不需要session</span>
                <span class="token punctuation">.</span><span class="token function">sessionManagement</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">sessionCreationPolicy</span><span class="token punctuation">(</span><span class="token class-name">SessionCreationPolicy</span><span class="token punctuation">.</span><span class="token constant">STATELESS</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">and</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment">// 过滤请求</span>
                <span class="token punctuation">.</span><span class="token function">authorizeRequests</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment">// 对于登录login 注册register 验证码captchaImage 允许匿名访问</span>
                <span class="token punctuation">.</span><span class="token function">antMatchers</span><span class="token punctuation">(</span><span class="token string">&quot;/login&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/register&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/captchaImage&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">anonymous</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment">// 静态资源，可匿名访问</span>
                <span class="token punctuation">.</span><span class="token function">antMatchers</span><span class="token punctuation">(</span><span class="token class-name">HttpMethod</span><span class="token punctuation">.</span><span class="token constant">GET</span><span class="token punctuation">,</span> <span class="token string">&quot;/&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/*.html&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/**/*.html&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/**/*.css&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/**/*.js&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/profile/**&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">permitAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">antMatchers</span><span class="token punctuation">(</span><span class="token string">&quot;/swagger-ui.html&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/swagger-resources/**&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/webjars/**&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/*/api-docs&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/druid/**&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">permitAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token comment">// 除上面外的所有请求全部需要鉴权认证</span>
                <span class="token punctuation">.</span><span class="token function">anyRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">authenticated</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">and</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">headers</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">frameOptions</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">disable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 添加Logout filter</span>
        httpSecurity<span class="token punctuation">.</span><span class="token function">logout</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">logoutUrl</span><span class="token punctuation">(</span><span class="token string">&quot;/logout&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">logoutSuccessHandler</span><span class="token punctuation">(</span>logoutSuccessHandler<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 添加JWT filter</span>
        httpSecurity<span class="token punctuation">.</span><span class="token function">addFilterBefore</span><span class="token punctuation">(</span>authenticationTokenFilter<span class="token punctuation">,</span> <span class="token class-name">UsernamePasswordAuthenticationFilter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 添加CORS filter</span>
        httpSecurity<span class="token punctuation">.</span><span class="token function">addFilterBefore</span><span class="token punctuation">(</span>corsFilter<span class="token punctuation">,</span> <span class="token class-name">JwtAuthenticationTokenFilter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        httpSecurity<span class="token punctuation">.</span><span class="token function">addFilterBefore</span><span class="token punctuation">(</span>corsFilter<span class="token punctuation">,</span> <span class="token class-name">LogoutFilter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 强散列哈希加密实现
     */</span>
    <span class="token annotation punctuation">@Bean</span>
    <span class="token keyword">public</span> <span class="token class-name">BCryptPasswordEncoder</span> <span class="token function">bCryptPasswordEncoder</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">BCryptPasswordEncoder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 身份认证接口
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">configure</span><span class="token punctuation">(</span><span class="token class-name">AuthenticationManagerBuilder</span> auth<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span>
    <span class="token punctuation">{</span>
        auth<span class="token punctuation">.</span><span class="token function">userDetailsService</span><span class="token punctuation">(</span>userDetailsService<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">passwordEncoder</span><span class="token punctuation">(</span><span class="token function">bCryptPasswordEncoder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br><span class="line-number">90</span><br><span class="line-number">91</span><br><span class="line-number">92</span><br><span class="line-number">93</span><br><span class="line-number">94</span><br><span class="line-number">95</span><br><span class="line-number">96</span><br><span class="line-number">97</span><br><span class="line-number">98</span><br><span class="line-number">99</span><br><span class="line-number">100</span><br><span class="line-number">101</span><br><span class="line-number">102</span><br><span class="line-number">103</span><br><span class="line-number">104</span><br><span class="line-number">105</span><br><span class="line-number">106</span><br></div></div><p>3、SysLoginService</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">login</span><span class="token punctuation">(</span><span class="token class-name">String</span> username<span class="token punctuation">,</span> <span class="token class-name">String</span> password<span class="token punctuation">,</span> <span class="token class-name">String</span> code<span class="token punctuation">,</span> <span class="token class-name">String</span> uuid<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">boolean</span> captchaOnOff <span class="token operator">=</span> configService<span class="token punctuation">.</span><span class="token function">selectCaptchaOnOff</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 验证码开关</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>captchaOnOff<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token function">validateCaptcha</span><span class="token punctuation">(</span>username<span class="token punctuation">,</span> code<span class="token punctuation">,</span> uuid<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// 用户验证</span>
    <span class="token class-name">Authentication</span> authentication <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token keyword">try</span>
    <span class="token punctuation">{</span>
        <span class="token comment">// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername</span>
        authentication <span class="token operator">=</span> authenticationManager
                <span class="token punctuation">.</span><span class="token function">authenticate</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">UsernamePasswordAuthenticationToken</span><span class="token punctuation">(</span>username<span class="token punctuation">,</span> password<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">BadCredentialsException</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token class-name">AsyncManager</span><span class="token punctuation">.</span><span class="token function">me</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token class-name">AsyncFactory</span><span class="token punctuation">.</span><span class="token function">recordLogininfor</span><span class="token punctuation">(</span>username<span class="token punctuation">,</span> <span class="token class-name">Constants</span><span class="token punctuation">.</span><span class="token constant">LOGIN_FAIL</span><span class="token punctuation">,</span> <span class="token class-name">MessageUtils</span><span class="token punctuation">.</span><span class="token function">message</span><span class="token punctuation">(</span><span class="token string">&quot;user.password.not.match&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">UserPasswordNotMatchException</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">else</span>
        <span class="token punctuation">{</span>
            <span class="token class-name">AsyncManager</span><span class="token punctuation">.</span><span class="token function">me</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token class-name">AsyncFactory</span><span class="token punctuation">.</span><span class="token function">recordLogininfor</span><span class="token punctuation">(</span>username<span class="token punctuation">,</span> <span class="token class-name">Constants</span><span class="token punctuation">.</span><span class="token constant">LOGIN_FAIL</span><span class="token punctuation">,</span> e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token class-name">AsyncManager</span><span class="token punctuation">.</span><span class="token function">me</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token class-name">AsyncFactory</span><span class="token punctuation">.</span><span class="token function">recordLogininfor</span><span class="token punctuation">(</span>username<span class="token punctuation">,</span> <span class="token class-name">Constants</span><span class="token punctuation">.</span><span class="token constant">LOGIN_SUCCESS</span><span class="token punctuation">,</span> <span class="token class-name">MessageUtils</span><span class="token punctuation">.</span><span class="token function">message</span><span class="token punctuation">(</span><span class="token string">&quot;user.login.success&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">LoginUser</span> loginUser <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">LoginUser</span><span class="token punctuation">)</span> authentication<span class="token punctuation">.</span><span class="token function">getPrincipal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">recordLoginInfo</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">.</span><span class="token function">getUserId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 生成token</span>
    <span class="token keyword">return</span> tokenService<span class="token punctuation">.</span><span class="token function">createToken</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br></div></div><p>4、JwtAuthenticationTokenFilter</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">JwtAuthenticationTokenFilter</span> <span class="token keyword">extends</span> <span class="token class-name">OncePerRequestFilter</span>
<span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">TokenService</span> tokenService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">doFilterInternal</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span> <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">,</span> <span class="token class-name">FilterChain</span> chain<span class="token punctuation">)</span>
            <span class="token keyword">throws</span> <span class="token class-name">ServletException</span><span class="token punctuation">,</span> <span class="token class-name">IOException</span>
    <span class="token punctuation">{</span>
        <span class="token class-name">LoginUser</span> loginUser <span class="token operator">=</span> tokenService<span class="token punctuation">.</span><span class="token function">getLoginUser</span><span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">isNotNull</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">isNull</span><span class="token punctuation">(</span><span class="token class-name">SecurityUtils</span><span class="token punctuation">.</span><span class="token function">getAuthentication</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            tokenService<span class="token punctuation">.</span><span class="token function">verifyToken</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">UsernamePasswordAuthenticationToken</span> authenticationToken <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">UsernamePasswordAuthenticationToken</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> loginUser<span class="token punctuation">.</span><span class="token function">getAuthorities</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            authenticationToken<span class="token punctuation">.</span><span class="token function">setDetails</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">WebAuthenticationDetailsSource</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">buildDetails</span><span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">SecurityContextHolder</span><span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setAuthentication</span><span class="token punctuation">(</span>authenticationToken<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        chain<span class="token punctuation">.</span><span class="token function">doFilter</span><span class="token punctuation">(</span>request<span class="token punctuation">,</span> response<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><p>5、自定义UserDetailsService</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserDetailsServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">UserDetailsService</span>
<span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">Logger</span> log <span class="token operator">=</span> <span class="token class-name">LoggerFactory</span><span class="token punctuation">.</span><span class="token function">getLogger</span><span class="token punctuation">(</span><span class="token class-name">UserDetailsServiceImpl</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">ISysUserService</span> userService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">SysPermissionService</span> permissionService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">UserDetails</span> <span class="token function">loadUserByUsername</span><span class="token punctuation">(</span><span class="token class-name">String</span> username<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">UsernameNotFoundException</span>
    <span class="token punctuation">{</span>
        <span class="token class-name">SysUser</span> user <span class="token operator">=</span> userService<span class="token punctuation">.</span><span class="token function">selectUserByUserName</span><span class="token punctuation">(</span>username<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">isNull</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;登录用户：{} 不存在.&quot;</span><span class="token punctuation">,</span> username<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span><span class="token string">&quot;登录用户：&quot;</span> <span class="token operator">+</span> username <span class="token operator">+</span> <span class="token string">&quot; 不存在&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">UserStatus</span><span class="token punctuation">.</span><span class="token constant">DELETED</span><span class="token punctuation">.</span><span class="token function">getCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getDelFlag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;登录用户：{} 已被删除.&quot;</span><span class="token punctuation">,</span> username<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span><span class="token string">&quot;对不起，您的账号：&quot;</span> <span class="token operator">+</span> username <span class="token operator">+</span> <span class="token string">&quot; 已被删除&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">UserStatus</span><span class="token punctuation">.</span><span class="token constant">DISABLE</span><span class="token punctuation">.</span><span class="token function">getCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getStatus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;登录用户：{} 已被停用.&quot;</span><span class="token punctuation">,</span> username<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span><span class="token string">&quot;对不起，您的账号：&quot;</span> <span class="token operator">+</span> username <span class="token operator">+</span> <span class="token string">&quot; 已停用&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">return</span> <span class="token function">createLoginUser</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">UserDetails</span> <span class="token function">createLoginUser</span><span class="token punctuation">(</span><span class="token class-name">SysUser</span> user<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">LoginUser</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getUserId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> user<span class="token punctuation">.</span><span class="token function">getDeptId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> user<span class="token punctuation">,</span> permissionService<span class="token punctuation">.</span><span class="token function">getMenuPermission</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br></div></div><h3 id="_8-2-授权"><a href="#_8-2-授权" class="header-anchor">#</a> 8.2 授权</h3> <p>1、 开启注解支持</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>2、方法上贴注解</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@PreAuthorize</span><span class="token punctuation">(</span><span class="token string">&quot;@ss.hasPermi('system:dict:query')&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/{dictCode}&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">AjaxResult</span> <span class="token function">getInfo</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span> <span class="token class-name">Long</span> dictCode<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token class-name">AjaxResult</span><span class="token punctuation">.</span><span class="token function">success</span><span class="token punctuation">(</span>dictDataService<span class="token punctuation">.</span><span class="token function">selectDictDataById</span><span class="token punctuation">(</span>dictCode<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>3、PermissionService</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * RuoYi首创 自定义权限实现，ss取自SpringSecurity首字母
 * 
 * @author ruoyi
 */</span>
<span class="token annotation punctuation">@Service</span><span class="token punctuation">(</span><span class="token string">&quot;ss&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PermissionService</span><span class="token punctuation">{</span>
    <span class="token comment">/**
     * 验证用户是否具备某权限
     * 
     * @param permission 权限字符串
     * @return 用户是否具备某权限
     */</span>
<span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">hasPermi</span><span class="token punctuation">(</span><span class="token class-name">String</span> permission<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>permission<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token class-name">LoginUser</span> loginUser <span class="token operator">=</span> <span class="token class-name">SecurityUtils</span><span class="token punctuation">.</span><span class="token function">getLoginUser</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">isNull</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token class-name">CollectionUtils</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">.</span><span class="token function">getPermissions</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token function">hasPermissions</span><span class="token punctuation">(</span>loginUser<span class="token punctuation">.</span><span class="token function">getPermissions</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> permission<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

 <span class="token comment">/**
     * 判断是否包含权限
     * 
     * @param permissions 权限列表
     * @param permission 权限字符串
     * @return 用户是否具备某权限
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span> <span class="token function">hasPermissions</span><span class="token punctuation">(</span><span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> permissions<span class="token punctuation">,</span> <span class="token class-name">String</span> permission<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> permissions<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token constant">ALL_PERMISSION</span><span class="token punctuation">)</span> <span class="token operator">||</span> permissions<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token class-name">StringUtils</span><span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span>permission<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br></div></div><h2 id="九、其他"><a href="#九、其他" class="header-anchor">#</a> 九、其他</h2> <h3 id="_9-1-个人中心"><a href="#_9-1-个人中心" class="header-anchor">#</a> 9.1 个人中心</h3> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007233843261.png" alt=""></strong></p> <h3 id="_9-2-切换主题"><a href="#_9-2-切换主题" class="header-anchor">#</a> 9.2 切换主题</h3> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007233917561.png" alt=""></strong></p> <h3 id="_9-3-切换菜单"><a href="#_9-3-切换菜单" class="header-anchor">#</a> 9.3 切换菜单</h3> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007234010482.png" alt=""></strong></p> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20211007234032045.png" alt=""></strong></p> <h2 id="十、小结与作业"><a href="#十、小结与作业" class="header-anchor">#</a> 十、小结与作业</h2> <ul><li>掌握学项目方法</li> <li>了解若依项目模块</li> <li>掌握若依项目基本操作</li> <li>掌握基于若依二次开发</li> <li>掌握若依认证与授权</li> <li>掌握若依其他操作</li></ul></div></div>  <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=Ruoyi" title="标签">#Ruoyi</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/0a481a/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">分布式事务与Seata落地</div></a> <a href="/pages/eed55d/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">脚手架-RuoYi-Cloud 微服务版</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/0a481a/" class="prev">分布式事务与Seata落地</a></span> <span class="next"><a href="/pages/eed55d/">脚手架-RuoYi-Cloud 微服务版</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0c07b2/"><div>
            IT杂货铺
            <!----></div></a> <span class="date">03-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/705b35/"><div>
            人事百问
            <!----></div></a> <span class="date">03-22</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/78eb56/"><div>
            MyBatis-Plus
            <!----></div></a> <span class="date">03-12</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:langfeiyes@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/langfeiyes" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2024-2024
    <span><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备18007927号-1</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.a2a00aa5.js" defer></script><script src="/assets/js/2.256f807a.js" defer></script><script src="/assets/js/65.6afc33db.js" defer></script>
  </body>
</html>
